﻿using System.Windows.Data;
using Caliburn.Micro;
using System.Collections.Generic;
using System;
using System.Collections.ObjectModel;

namespace MIXer.Customization
{
    public class ViewableCollection<T> : ListCollectionView
    {
        #region Fields
        private Func<T, bool> _filterCondition;
        #endregion

        #region Constructors
        public ViewableCollection(ObservableCollection<T> collection)
            :base(collection)
        {
            this.Filter = FilterImpl;
        }
        #endregion

        #region Methods
        public void FilterWhen(Func<T, bool> condition)
        {
            _filterCondition = condition;
        }
        private bool FilterImpl(object item)
        {
            if (_filterCondition == null)
                return true;

            return _filterCondition((T)item);
        }
        #endregion
    }
}
